package com.lvyq.myplayer.adapter.current

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.lvyq.myplayer.common.util.DataOperationUtils
import com.lvyq.myplayer.parcelable.SongInfoData
import com.lvyq.myplayer.util.ThreadUtil
import com.lvyq.myplayer.widget.AudioListItemView

/**
 * 文件描述：CurrentPlayLstAdapter  当前播放列表
 * 作者：lvyq
 * 创建时间：2025-06-24
 * 修改时间：2025-06-24
 */
class CurrentPlayLstAdapter(var context: Context):RecyclerView.Adapter<CurrentPlayLstAdapter.CurrentPlayLstViewHolder>(){

    var list= ArrayList<SongInfoData>()

    // 定义点击事件接口
    interface OnItemClickListener {
        fun onItemClick(data: SongInfoData, position: Int)

        fun onItemClickDel( position: Int)
    }

    private var onItemClickListener: OnItemClickListener? = null

    fun setOnItemClickListener(listener: OnItemClickListener) {
        this.onItemClickListener = listener
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CurrentPlayLstViewHolder {

        return CurrentPlayLstViewHolder(AudioListItemView(parent.context))
    }

    override fun getItemCount(): Int {
       return list.size
    }

    override fun onBindViewHolder(holder: CurrentPlayLstViewHolder, position: Int) {
        val data = list[position]
        val item = holder.itemView as AudioListItemView
        item.setData(data)
        //添加点击事件
        item.setOnClickListener{
            onItemClickListener?.onItemClick(data,position)
        }
        //点击删除
        item.playDel.setOnClickListener {
            onItemClickListener?.onItemClickDel(position)

        }

    }

    fun initData(playList: ArrayList<SongInfoData>) {
        list=playList
        notifyDataSetChanged()
    }

    /**
     * 主要用于切换歌曲时，更新播放状态
     */
    fun refreshPlayPosition(position: Int) {
        notifyDataSetChanged()
    }


    inner class CurrentPlayLstViewHolder(view:View):RecyclerView.ViewHolder(view) {

    }


}